<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org"
      xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity4">
<head th:include="base/head.html::static">
<title>假条</title>

<!--标签插件-->
<link rel="stylesheet" th:href="@{/js/jquery-tags-input/jquery.tagsinput.min.css}">

</head>
  
<body>
<div class="lyear-layout-web">
  <div class="lyear-layout-container">
    <!--左侧导航-->
    <aside class="lyear-layout-sidebar" th:include="base/base.html::left"></aside>

    <!--头部信息-->
    <header class="lyear-layout-header" th:include="base/base.html::header"></header>
    
    <!--页面主要内容-->
    <main class="lyear-layout-content">
      
      <div class="container-fluid">
        
        <div class="row">
          <div class="col-lg-12">
            <div class="card">
              <div class="card-body">
                
                <form action="/leave-note/apply" method="post" class="row">

                  <div class="form-group col-md-12">
                    <div class="col-md-2">
                      <label for="dep">学院</label>
                      <input class="form-control" type="text" th:value="${leaveNote.departmentName}" readonly>
                    </div>
                    <div class="col-md-2">
                      <label for="class" >班级</label>
                      <input class="form-control" type="text" th:value="${leaveNote.className}" readonly>
                    </div>
                    <div class="col-md-3">
                      <label for="userNum">学&nbsp;&nbsp;&nbsp;&nbsp;号</label>
                      <input th:value="${leaveNote.userId}" type="text" class="form-control"   readonly/>
                    </div>
                    <div class="col-md-2">
                      <label for="realName">姓&nbsp;&nbsp;&nbsp;&nbsp;名</label>
                      <input th:value="${leaveNote.userName}" type="text" class="form-control" readonly/>
                    </div>
                    <div class="col-md-2">
                      <label for="courseName">课程名字</label>
                      <div class="dropdown">
                        <input class="form-control" type="text" th:value="${leaveNote.courseName}" readonly>
                      </div>
                    </div>
                  </div>



                  <div class="form-group col-md-12">&nbsp;</div>

                  <div class="form-group col-md-12">

                    <div class="col-md-6"><label for="timeStart">开始时间</label>
                      <input readonly th:value="${#dates.format(leaveNote.timeStart,'yyyy-MM-dd HH:mm:ss')}" class="form-control" type="text"/>
                    </div>
                    <div class="col-md-6">
                      <label for="timeEnd">结束时间</label>
                      <input readonly th:value="${#dates.format(leaveNote.timeEnd,'yyyy-MM-dd HH:mm:ss')}" class="form-control" type="text" id="timeEnd"/>
                    </div>

                  </div>

                  <div class="form-group col-md-12">&nbsp;</div>

                  <div class="form-group col-md-12">

                    <label for="cause">理由</label>
                    <textarea th:text="${leaveNote.cause}" readonly class="form-control" id="cause" name="cause"
                              rows="5" value="" placeholder="说明请假原因"></textarea>
                  </div>

                  <div class="form-group col-md-12">&nbsp;</div>

                  <div sec:authorize="hasRole('ROLE_STUDENT')" class="form-group col-md-12">
                    <div class="col-md-4">
                      <label>审核状态 ：</label>
                      <span th:if="${leaveNote.state == 1}" class="label label-success">审核通过</span>
                      <span th:if="${leaveNote.state == 0}" class="label label-warning">未审核</span>
                      <span th:if="${leaveNote.state == -1}" class="label label-danger">审核未通过</span>
                    </div>
                    <div class="col-md-4 col-md-offset-3" >
                      <label>审核人：</label>
                      <label th:text="${leaveNote.teacherName}">彭星浪</label>
                    </div>

                  </div>


                  <div class="form-group col-md-12">
                    <a sec:authorize="hasRole('ROLE_TEACHER')" th:if="${leaveNote.state== 0}" type="button" class="btn btn-success col-md-offset-1 btn-w-lg" id="success" onclick="approLeaveNote(this)">通过</a>
                    <a sec:authorize="hasRole('ROLE_TEACHER')" th:if="${leaveNote.state== 0}" type="button" class="btn btn-danger col-md-offset-1 btn-w-lg" onclick="approLeaveNote(this)">不通过</a>
                    <button type="button" class="btn btn-default col-md-offset-1 btn-w-lg" onclick="javascript:history.back(-1);return false;">返 回</button>
                  </div>
                </form>
       
              </div>
            </div>
          </div>
          
        </div>
        
      </div>
      
    </main>
    <!--End 页面主要内容-->
  </div>
</div>



<!--时间选择插件-->
<script th:src="@{/js/bootstrap-datetimepicker/moment.min.js}"></script>
<script th:src="@{/js/bootstrap-datetimepicker/bootstrap-datetimepicker.min.js}"></script>
<script th:src="@{/js/bootstrap-datetimepicker/locale/zh-cn.js}"></script>
<script type="text/javascript" th:inline="javascript">
  var approLeaveNote=function (element) {
    var  text=element.text;
    //alert(JSON.stringify(text));
    var success=$('#success').text();
    var state=text==success?1:-1;
    alert(state);

    //获取名字
    var teacherName=[[${session.user.realName}]];
    var ids=[];
    ids.push([[${leaveNote.id}]]);
   // alert(ids);
    axios({
      method:'put',
      url:"/leave-note/appro",
      data:{
        state: state,
        ids:ids,
        teacherName:teacherName
      }
    }).then(
            function (response) {
              //为什么会发两次请求
              alert(response.data);
              if(response.data=='审核成功'){
                window.location.replace("/leave-note/appro/1");
              }
            }
    );

  }

</script>
</body>
</html>